/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view.alternativesrating;

import data.ACStorage;
import javax.swing.table.AbstractTableModel;
import model.AlternativeRanks;
import model.Criteria;

/**
 *
 * @author Luke
 */
public class TblModelAverageValuesAlternatives extends AbstractTableModel {

    Criteria criteria;

    public TblModelAverageValuesAlternatives(Criteria criteria) {
        this.criteria = criteria;
    }

    @Override
    public int getRowCount() {
        return ACStorage.getInstance().getGoal().getListAlternative().size();
    }

    @Override
    public int getColumnCount() {
        return ACStorage.getInstance().getGoal().getListAlternative().size() + 2;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
//        int br = 0;
//        double s = 1;
//        double prosek;
//        for (int j = 0; j <= ACStorage.getInstance().getGoal().getListAlternative().size(); j++) {
//            s += criteria.getAlternativeRankInList(
//                    ACStorage.getInstance().getGoal().getListAlternative().get(j),
//                    ACStorage.getInstance().getGoal().getListAlternative().get(rowIndex)).getMark();
//            br++;
//        }
//        prosek = s / br;
//        criteria.getAverageValue().add(prosek);
//        return prosek;
        if (columnIndex == 0) {
            return ACStorage.getInstance().getGoal().getListAlternative().get(rowIndex);
        } else if (columnIndex > ACStorage.getInstance().getGoal().getListAlternative().size()) {
            return criteria.getAverageValue().get(rowIndex);
        } else {
            AlternativeRanks ar = criteria.getAlternativeRankInList(
                    ACStorage.getInstance().getGoal().getListAlternative().get(columnIndex - 1),
                    ACStorage.getInstance().getGoal().getListAlternative().get(rowIndex));
            return ar.getNormalizedMark();
        }


    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return false;
    }

    @Override
    public String getColumnName(int column) {
        if (column == 0) {
            return criteria.getName();
        } else if (column > ACStorage.getInstance().getGoal().getListAlternative().size()) {
            return "Average";
        } else {
            return ACStorage.getInstance().getGoal().getListAlternative().get(column - 1).getName();
        }
    }
}
